libname in 'x:\Donnanew';
options nolabel;

***For REStat paper "Breastfeeding and Children's Early Cognitive Outcomes."

data in.pch082;
set in.pch08;
keep childid childyob newimmi mompcraw home97 warm97 le55lb wic97
      bfeed marbirth femch momhgc dadhgc lninc97 regne regnc regw regs cath bapt
	  bf0 bf1 bf23 bf45 bf6p lw56 ap56 year56 glt35 g3537 fborn sborn black hisp ageb
	  ch97prwt ch02prwt 
      regdv momhgcdv dadhgcdv mompcdv mardv reldv wicdv warmdv borddv pcg97id age97 age02;

if bfeed = 0 then bfmo = 0;
*form bf dummy variables;
bf0 = .;
bf1 = .; 
bf23 = .; 
bf45 = .; 
bf6p = .;
if bfmo = 0 then do;
bf0 = 1;
bf1 = 0; 
bf23 = 0; 
bf45 = 0; 
bf6p = 0;
end;
if (bfmo gt 0 and bfmo le 1) then do;
bf0 = 0;
bf1 = 1; 
bf23 = 0; 
bf45 = 0; 
bf6p = 0;
end;
if (bfmo gt 1 and bfmo le 3) then do;
bf0 = 0;
bf1 = 0; 
bf23 = 1; 
bf45 = 0; 
bf6p = 0;
end;
if (bfmo gt 3 and bfmo lt 6) then do;
bf0 = 0;
bf1 = 0; 
bf23 = 0; 
bf45 = 1; 
bf6p = 0;
end;
if (bfmo ge 6) then do;
bf0 = 0;
bf1 = 0; 
bf23 = 0; 
bf45 = 0; 
bf6p = 1;
end;

*test scores--mean 0 and sd 1;
lw97 = (lw97 - 100)/15;
ap97 = (ap97 - 100)/15;
lw02 = (lw02 - 100)/15;
ap02 = (ap02 - 100)/15;

*now, scores for 5-6 year olds;
lw56 = .;
ap56 = .;
if (age97 ge 5 and age97 lt 7) then lw56 = lw97;
if (age97 ge 5 and age97 lt 7) then ap56 = ap97;
*same sample;
if lw56 = . then ap56 = .;
if ap56 = . then lw56 = .;
if lw56 ne . then year56 = 1997;

if (lw56 = . and ap56 = . and age02 ge 5 and age02 lt 7) then do;
    lw56 = lw02;
	ap56 = ap02;
	year56 = 2002;
end;
*same sample;
if lw56 = . then ap56 = .;
if ap56 = . then lw56 = .;
if lw56 = . then year56 = .;

*log of family income;
**1982-84 prices;
faminc97 = faminc97*.637;
if faminc97 gt 0 then do;
lninc97 = log(faminc97);
end;

*gestational weeks;
glt35 = .;
g3537 = .;
if (gestwk gt 10 and gestwk lt 35) then do;
   glt35 = 1;
   g3537 = 0;
end;
if (gestwk ge 35 and gestwk le 37) then do;
   glt35 = 0;
   g3537 = 1;
end;
if gestwk gt 37 then do;
   glt35 = 0;
   g3537 = 0;
end;

*first born, second born;
fborn = .;
sborn = .;
if border = 1 then do;
fborn = 1;
sborn = 0;
end;
if border = 2 then do;
fborn = 0;
sborn = 1;
end;
if border gt 2 then do;
fborn = 0;
sborn = 0;
end;

**see if can code up consistent race for mother;
black = .;
hisp = .;
if (pcgbl = 0 and pcghi = 0 and chblack = 0 and chhisp = 0) then do;
   black = 0;
   hisp = 0;
end;
if (pcgbl = 1 and pcghi = 0 and chblack = 1 and chhisp = 0) then do;
   black = 1;
   hisp = 0;
end;
if (pcgbl = 0 and pcghi = 1 and chblack = 0 and chhisp = 1) then do;
   black = 1;
   hisp = 0;
end;
**use child to fill in for missing parent info.;
if (pcgbl = . and pcghi = . and chblack ne . and chhisp ne .) then do;
   black = chblack;
   hisp = chhisp;
end;
**only 42 cases of 953 where mother/child race/ethnicity differs, going with mother here;
if (black = . and hisp = .) then do;
   black = pcgbl;
   hisp = pcghi;
end;

**age at birth;
ageb = .;
ageb = childyob - momyob;
if mommob gt childmob then ageb = ageb - 1;

**fill in a few with '97 info., although not many get filled in;
if momhgc = . then momhgc = mhgc97;
if dadhgc = . then dadhgc = dhgc97;

*start adding some dummy variables;
regdv = 0;
if (regnc = .) then regdv = 1;

momhgcdv = 0;
if momhgc = . then momhgcdv = 1;

dadhgcdv = 0;
if dadhgc = . then dadhgcdv = 1;

mompcdv = 0;
if mompcraw = . then mompcdv = 1;

mardv = 0;
if marbirth = . then mardv = 1;

reldv = 0;
if bapt = . then reldv = 1;

wicdv = 0;
if wic97 = . then wicdv = 1;

warmdv = 0;
if warm97 = . then warmdv = 1;

borddv = 0;
if fborn = . then borddv = 1;

**deletions;
**limit to primary caregiver in '97 is biological mother;
if relpcg97 = 1;

*non-missing bf information;
if bf1 ne .;

*non-missing test scores;
if lw56 ne .;

**these just missing a few obs.;
if lninc97 ne .;
if le55lb ne .;
if glt35 ne .;


proc means;
run;
